<?php
/**
 * Created by PhpStorm.
 * User: fengzi
 * Date: 2019/4/4
 * Time: 14:13
 */

namespace app\admin\controller;
use app\admin\logic\OperationLogic;
use app\admin\logic\RoleLogic;
use think\facade\Request;
use app\admin\logic\ruleLogic;
class Role extends Base{

    public function __construct(){
        parent::__construct();
        $this->operationLogic = new OperationLogic();
        $this->roleLogic = new RoleLogic();
    }

    public function index(){
       return $this->fetch();
    }

    /**
     * 异步获取角色列表
     * @return \think\response\Json
     */
    public function ajaxIndex(){
        $where = Request::param();
        $res = $this->roleLogic->roleList($where, self::$nowPage);
        return json($res);
    }

    /**
     * 编辑角色
     * @return mixed
     */
    public function add(){
        $id = Request::param('id');
        $act = 'add';
        $info = [];
        if ($id){
            $act = 'edit';
            $info = $this->roleLogic->info($id);
            $this->assign('info',$info ['data']);
        }
        $allOperation = $this->operationLogic->getAllMenu(0, true);
        $this->assign('act', $act);
        $this->assign('operation_list', $allOperation['data']);
        return $this->fetch();
    }

    //编辑角色
    public function handle(){
        $data = Request::param();
        $res = $this->roleLogic->handle($data);
        return json($res);
    }

    //删除角色
    public function del(){
        $id = Request::param('id');
        $res = $this->ruleService->del($id);
        return json($res);
    }

}